import { ChangeDetectionStrategy, Component, ElementRef, Input, OnInit, ViewEncapsulation  } from '@angular/core';
import { ApesSizeLDSType, ApesUpdateHostClassService } from '@shared/apes/core';


@Component({
  selector           : 'apes-button-group',
  exportAs: 'apesButtonGroup',
  changeDetection: ChangeDetectionStrategy.OnPush,
  encapsulation: ViewEncapsulation.None,
  preserveWhitespaces: false,
  providers: [ApesUpdateHostClassService],
  template           : `
    <ng-content></ng-content>
  `
})
export class ApesButtonGroupComponent implements OnInit {
  private _size: ApesSizeLDSType;


  @Input()
  get apesSize():  ApesSizeLDSType {
    return this._size;
  }

  set apesSize(value:  ApesSizeLDSType) {
    this._size = value;
    this.setClassMap();
  }

  constructor(private apesUpdateHostClassService: ApesUpdateHostClassService, private elementRef: ElementRef) {}

  setClassMap(): void {
    const prefixCls = 'apes-btn-group';
    const classMap = {
      [prefixCls]: true,
      [`${prefixCls}-lg`]: this.apesSize === 'large',
      [`${prefixCls}-sm`]: this.apesSize === 'small'
    };
    this.apesUpdateHostClassService.updateHostClass(this.elementRef.nativeElement, classMap);
  }

  ngOnInit(): void {
    this.setClassMap();
  }

}
